<?php
/**
 * @Notes: 机器学习-最小二乘法预测天气
 * @Interface getCondition
 * @Return mixed
 * @Author: bqs
 * @Time: 2021/4/19 15:28
 */

namespace app\common\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Argument;
use think\console\input\Option;
use think\Db;
use think\facade\Hook;
use think\facade\Log;
use Phpml\Regression\LeastSquares;
use QL\QueryList;

class PredictWeather extends Command
{

    protected function configure()
    {
        $this->setName('predict:weather')
            ->setDescription('最小二乘法预测天气');
    }

    protected function execute(Input $input, Output $output)
    {
        $output->writeln("!!!predict——weather!!!");

        // $url = 'https://www.keyunzhan.com/lishitianqi/guangzhou/';
        // $high = QueryList::get($url)->find('table.yuBaoTable')->find('tr')->map(function ($tr){
        //     return $tr->find('td:eq(1)')->texts();
        // });
        //
        // $targets = $high->toArray();
        // foreach ($targets as &$target){
        //     $target = intval($target[0]);
        // }
        // unset($target);
        // array_shift($targets);
        // $total = count($targets);
        // $samples = [];
        // for($i=0;$i<$total;$i++){
        //     $samples[] = [$i];
        // }

        $samples = [[0],[1],[2],[3],[4],[5],[6]];
        $targets = [15,20,31,19,15,89,15];
        $total = count($targets);

        print_r($targets);
        echo chr(10);
        $regression = new LeastSquares();
        $regression->train($samples, $targets);

        $nextDay = $total+1;
        $nextDayHigh = $regression->predict([$nextDay]);

        echo 'next day : ';
        echo(round($nextDayHigh));
        echo chr(10);

        //$output->writeln(json_encode($high,JSON_UNESCAPED_UNICODE));
    }


}